package com.example.mapp.buildSql;

import com.example.ext.entity.ExtSystemAuthor;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created by youkun on 2017/9/2.
 */
public class SystemAuthorMappSql {

    /**
     * 查询权限列表
     * @param extSystemAuthor
     * @return
     */
    public String querySystemAuthorList(final ExtSystemAuthor extSystemAuthor){

        String select = " s.id,s.author_describe, s.author_name,s.author_url," +
                "s.parent_id,s.author_icon,s.author_id,s.author_type,b.parent_name,s.sys_type ";

        String table = "system_author as s left join (select author_name as parent_name," +
                "id from system_author) b on s.parent_id = b.id";

       String whereParam="";
        if(null!=extSystemAuthor.getAuthorName() && extSystemAuthor.getAuthorName().length()>0){
            extSystemAuthor.setAuthorName('%'+extSystemAuthor.getAuthorName()+'%');
            whereParam+=" and s.author_name like #{authorName}";
        }
        if(null!=extSystemAuthor.getSysType() && extSystemAuthor.getSysType().length()>0){
            //extSystemAuthor.setAuthorName('%'+extSystemAuthor.getSysType()+'%');
            whereParam+=" and s.sys_type = #{sysType}";
        }
        String  where = "1=1 " +whereParam;
        return new SQL(){{
            SELECT(select);
            FROM(table);
            WHERE(where);
        }
        }.toString();
    }

}
